<template>
  <el-container class="app-container">
    <el-header v-if="authStore.isAuthenticated">
      <el-menu mode="horizontal" router>
        <el-menu-item index="/">首页</el-menu-item>
        <el-menu-item index="/objectives">目标管理</el-menu-item>
        <el-menu-item index="/teams">团队管理</el-menu-item>
        <el-menu-item index="/profile" class="profile-menu">
          <el-dropdown>
            <span class="el-dropdown-link">
              {{ authStore.user.username }}
              <el-icon class="el-icon--right"><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="handleLogout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </el-menu-item>
      </el-menu>
    </el-header>

    <el-main>
      <router-view></router-view>
    </el-main>

    <el-footer v-if="showFooter">
      <p>&copy; 2024 OKR管理系统. All rights reserved.</p>
    </el-footer>
  </el-container>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from './store/auth'
import { ArrowDown } from '@element-plus/icons-vue'

const router = useRouter()
const authStore = useAuthStore()

const showFooter = computed(() => {
  return router.currentRoute.value.path === '/'
})

const handleLogout = () => {
  authStore.logout()
  router.push('/login')
}
</script>

<style>
.app-container {
  min-height: 100vh;
}

.el-header {
  padding: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.el-menu {
  border-bottom: none;
}

.profile-menu {
  float: right;
}

.el-dropdown-link {
  cursor: pointer;
  display: flex;
  align-items: center;
}

.el-main {
  padding: 20px;
  background-color: #f5f7fa;
}

.el-footer {
  text-align: center;
  color: #909399;
  padding: 20px;
  background-color: #fff;
}
</style>